package com.example.barcodeapp.ui.wode.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.barcodeapp.R;
import com.example.barcodeapp.base.BaseActivity;
import com.example.barcodeapp.interfaces.IBasePersenter;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.OnePresenterKeChengXiangQing;
import com.example.barcodeapp.persenter.OnePresenterwodekechenglanmu;
import com.example.barcodeapp.ui.own.bean.LanMuBean;
import com.example.barcodeapp.ui.wode.fragment.MiFragment;
import com.example.barcodeapp.ui.wode.fragment.MusicGongKaiFragment;
import com.example.barcodeapp.ui.wode.fragment.MusicPeiLianFragment;
import com.example.barcodeapp.ui.wode.fragment.MusicQuanFragment;
import com.example.barcodeapp.ui.wode.fragment.MusicXiLeiFragment;
import com.example.barcodeapp.ui.wode.fragment.MusicZhiBoFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class KeChengActivity extends BaseActivity<IOwn.Persenterwodekechenglanmu> implements IOwn.Viewwodekecheng {


    @BindView(R.id.tl_class)
    TabLayout tlClass;
    @BindView(R.id.vp_class)
    ViewPager vpClass;

    @Override
    protected int getLayout() {
        return R.layout.activity_ke_cheng;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected OnePresenterwodekechenglanmu initPersenter() {
        return new OnePresenterwodekechenglanmu();
    }

    @Override
    protected void initData() {
            persenter.getwodekechenglanmu();
    }
    @Override
    public void getwodekechenglanmu(LanMuBean xiLieKeBean) {
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new MusicQuanFragment());
        fragments.add(new MusicXiLeiFragment());
        fragments.add(new MusicPeiLianFragment());
        fragments.add(new MusicZhiBoFragment());
        fragments.add(new MusicGongKaiFragment());
        fragments.add(new MiFragment());//getChildFragmentManager
        vpClass.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });
        tlClass.setupWithViewPager(vpClass);
        tlClass.setSelectedTabIndicatorHeight(0);
        tlClass.getTabAt(0).setText("全部").isSelected();
        for (int i = 1; i < xiLieKeBean.getData().size(); i++) {
            tlClass.getTabAt(i).setText(xiLieKeBean.getData().get(i).getLanmu());
        }
        View root = LayoutInflater.from(this).inflate(R.layout.cch_tab_text_item, null);
        TextView tv_name = root.findViewById(R.id.tv_name);
        tv_name.setTextSize(20);
        tv_name.setText("全部");
        tlClass.getTabAt(0).setCustomView(root);
        tlClass.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {

                View root = LayoutInflater.from(KeChengActivity.this).inflate(R.layout.cch_tab_text_item, null);
                TextView tv_name = root.findViewById(R.id.tv_name);
                tv_name.setTextSize(20);
                tv_name.setText(tab.getText());
                tab.setCustomView(root);

            }
            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
}